package com.gzhryc.common.redis;

import com.gzhryc.common.StringTools;
import com.gzhryc.common.redis.models.RedisConfig;

import java.util.concurrent.ConcurrentHashMap;

public class RedisToolsManager {

	private static RedisToolsManager me;
	
	public static RedisToolsManager self() {
		if(me == null) {
			me = new RedisToolsManager();
		}
		return me;
	}

	ConcurrentHashMap<String ,RedisTools> store;
	
	public RedisToolsManager() {
		this.store = new ConcurrentHashMap<String, RedisTools>();
	}
	
	public void addRedisTools(String key,RedisTools redisTools) {
		this.store.put(key, redisTools);
	}
	
	public void addRedisTools(String key,String host,Integer port,String password) {
		RedisTools redisTools = new RedisTools();
		redisTools.initial(host, port, password);
		this.store.put(key, redisTools);
	}

	public void addRedisTools(String key, RedisConfig config) {
		RedisTools redisTools = new RedisTools();
		redisTools.initial(config.getHost(), config.getPort(), config.getPwd());
		this.store.put(key, redisTools);
	}


	public RedisTools getRedisTools(String key) {
		if(StringTools.isNotBlank(key)) {
			return this.store.get(key);
		}
		return null;
	}
}
